<?php
if (!defined('IN_CONTEXT')) die('access violation error!');

class lib_session
{
	public static $session;
	
	public static function init()
	{
		$current_class = __CLASS__;
		if(self::$session instanceof $current_class)
		{
			return self::$session;
		}
		else
		{
			session_start();
			self::$session = new $current_class();
			return self::$session;
		}
	}
	
	private function __construct()
	{
		
	}
	
	
	public function setSession($arr = array())
	{
		foreach($arr as $k => $v)
		{
			$_SESSION[$k] = $v;
		}
	}
	
	public function getSession($key = false)
	{
		if(!$key)
		{
			return $_SESSION;
		}
		else
		{
			if(empty($_SESSION[$key])) return null;
			return $_SESSION[$key];
		}
	}
	
	public function destorySession($key = false)
	{
		if(!$key)
		{
			setcookie('PHPSESSID','',time()-31600000);//应对session目录没有权限的情况
			@session_destroy();
		}
		else
		{
			unset($_SESSION[$key]);//session目录没有权限可能失效
		}
	}
	
}
?>